package org.medusa.config;

import java.io.BufferedWriter;  
import java.io.File;  
import java.io.FileInputStream;  
import java.io.FileWriter;  
import java.util.Properties;  

public class INIFile {  
private static Properties ini = null;  
    //设置INI文件  
    static File file=new File("src/world.ini");  
    static {  
        try {  
            ini = new Properties ();  
            //加载文件  
            ini.load (new FileInputStream (file));  
        }catch (Exception ex) {  
            ex.printStackTrace();  
        }  
    }  
    private INIFile() {  
    }  
    /** 
     * 读取INI信息 
     * */  
    public static String IniKey (String key) {  
        if(!ini.containsKey (key)) {  
            return "";  
        }  
        return ini.get(key).toString ();  
    }  
    /** 
     * 修改INI信息 
     * */  
    public static void IniKey (String key, String value) {  
        if(!ini.containsKey (key)) {  
            return;  
        }  
        ini.put (key, value);  
    }  
    /** 
     * 保存INI信息 
     * */  
    public static void SaveIni (String k[]) {  
        try {  
            FileWriter fw = new FileWriter (file);  
            BufferedWriter bw = new BufferedWriter (fw);  
            for (int i = 0; i < k.length; i++) {  
                bw.write (k[i] + "=" + IniKey (k[i]));  
                bw.newLine ();  
            }  
            bw.close ();  
            fw.close ();  
        }catch (Exception ex) {  
            ex.printStackTrace();  
        }  
    }  
    
    
    /*
 // Byte
 	public byte ReadByte(String key) {

 	}

 	public void WriteByte(byte val) {

 	}



 	// Int8
 	public byte ReadInt8() {

 	}

 	public void WriteInt8(byte val) {

 	}

 	// Int16
 	public short ReadInt16() {

 	}

 	public void WriteInt16(short val) {

 	}

 	// Int32
 	public int ReadInt32() {

 	}

 	public void WriteInt32(int val) {

 	}

 	// Int64
 	public long ReadInt64() {

 	}

 	public void WriteInt64(long val) {

 	}

 	// Float
 	public float ReadFloat32() {

 	}

 	public void WriteFloat32(float val) {

 	}

 	// Double
 	public double ReadFloat64() {

 	}

 	public void WriteFloat64(double val) {

 	}

 	// String
 	public String ReadString() {

 	}

 	public void WriteString(String val) {

 	}

 	// byte[]
 	public void Read(byte[] dst, int len) {

 	}

 	public void Write(byte[] src, int len) {

 	}
 	*/
}  